$(function(){
	$('#register').on('click',function(){
		var adminName= $('#adminName').val();
		var adminPassword= $('#adminPassword').val();
		var confirmPassword= $('#confirmPassword').val();
		
		if(adminName == "" || adminPassword == ""){
			return BSTYUN.dialog.warn("<span style='color:#000;'>请输入完整的信息！</span>");
		}else if (!checkPassword(adminPassword,confirmPassword)){
			return BSTYUN.dialog.warn("<span style='color:#000;'>两次输入密码不一致！</span>");
		}else{
			$.ajax({
				type : "POST",
				url : "/loginAdmin/register",
				async : false,
				data : {
					adminName : adminName,
					adminPassword : adminPassword
				},
				dataType: 'json',
				success:function(data){
					if(data.isSuccess == "ok") {
						BSTYUN.dialog.ok("<span style='color:#000;'>恭喜您注册成功！</span>",function(){
							location.href = "/loginAdmin";
						});
						
					}else if(data.isSuccess == "userNameError") {
						BSTYUN.dialog.warn("<span style='color:#000;'>用户名已存在！</span>");
					}else if(data.isSuccess == "registerFail") {
						BSTYUN.dialog.warn("<span style='color:#000;'>注册失败！请重新注册！</span>");
					}
				}
			})
		}
	})	
});

function checkPassword(adminPassword,confirmPassword){
	if(adminPassword != "" && confirmPassword != ""){
		if(adminPassword != confirmPassword) {
			return false;
		}else{
			return true;
		}
	}else{
		return false;
	}
}




